import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        预期浏览器会发一个 形如  /getParameter?studentId=11&classId=22 类似的请求
//        借助req里的getParameter方法就能拿到 query string 中的键值对内容, getParameter得到的是string类型的结果
//        根据key获取value
        String studentId = req.getParameter("studentId");
        String classId = req.getParameter("classId");
//        resp.setContentType("text/html"); //让返回类型为HTML的文本格式
//        resp.setCharacterEncoding("utf8"); //显示的告诉浏览器字符集编码方式
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write("studentId = " + studentId + " classId = " + classId);
    }
}
